package com.example.springaop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
@Aspect
public class AspectDemo1 {
    @Pointcut("execution(* com.example.springaop.controller.*.*(..))")
     public void pt(){}

    @Around("pt()")
    public Object aroundTest(ProceedingJoinPoint point) throws Throwable {
        //通知
        log.info("Around 开始执行");
        //执行目标函数
        Object result = point.proceed();
        //结束打印
        log.info("Around 结束执行");
        return result;
    }

    @Before("execution(* com.example.springaop.controller.*.*(..))")
    public void beforeTest(){
        log.info("before 开始执行");
    }

    @After("execution(* com.example.springaop.controller.*.*(..))")
    public void afterTest(){
        log.info("after 开始执行");
    }

    @AfterReturning("execution(* com.example.springaop.controller.*.*(..))")
    public void afterReturnTest(){
        log.info("afterReturn 开始执行");
    }

    @AfterThrowing("execution(* com.example.springaop.controller.*.*(..))")
    public void afterThrowTest(){
        log.info("afterThrow 开始执行");
    }
}
